<template>
    <div style=" position: relative;"><el-card>
            <template #header>
                <!-- 搜索 -->
                <div>
                    <el-select style="width:160px" v-model="find_data.routeSimpleName" placeholder="请选择行程简称" clearable>
                        <el-option v-for="item in routeSimpleName_list" :key="item.value" :label="item.label"
                            :value="item.value" />
                    </el-select>
                    <!-- <el-select style="width:120px;margin-left: 10px;" v-model="find_data.serviceMan" placeholder="请选业务员"
                    clearable>
                    <el-option v-for="item in getServiceMans_list" :key="item.ftUserId" :label="item.realName"
                        :value="item.ftUserId" />
                </el-select> -->
                    <el-select style="width:100px;margin-left: 10px;" v-model="find_data.timeType"
                        :placeholder="'时间类型'">
                        <el-option :label="'用车时间'" :value="'0'"></el-option>
                        <el-option :label="'下单时间'" :value="'1'"></el-option>
                        <el-option :label="'续团时间'" :value="'2'"></el-option>
                    </el-select>
                    <el-date-picker :default-time="defaultTime" style="margin-left: 10px;width: 340px;"
                        v-model="timeTypeTime" @change="timeTypeTime_btn" type="datetimerange" start-placeholder="开始时间"
                        end-placeholder="结束时间" format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" />
                    <el-select v-model="find_data.orderByCondition" :placeholder="'排序'"
                        style="width: 80px;margin-left: 10px;">
                        <el-option :label="'升序'" :value="'0'"></el-option>
                        <el-option :label="'降序'" :value="'1'"></el-option>
                    </el-select>

                    <el-input style="width: 140px;margin-left: 10px;" placeholder="订单号" v-model="find_data.orderNum">
                    </el-input>

                    <el-input style="width: 220px;margin-left: 10px;" placeholder="行程详情/客户/驾驶员/业务员备注"
                        v-model="find_data.details">
                    </el-input>
                    <el-select clearable v-model="find_data.statusList" multiple collapse-tags :placeholder="'订单状态'"
                        style="width: 180px;margin-left: 10px;">
                        <el-option v-for="it in orderStates" :label="it.name" :key="it.id" :value="it.id">
                        </el-option>
                    </el-select>

                    <el-select clearable v-model="find_data.payWay" :placeholder="'支付方式'"
                        style="width: 180px;margin-left: 10px;">
                        <el-option v-for="it in payWay_List" :label="it.name" :key="it.id" :value="it.id">
                        </el-option>
                    </el-select>

                    <div style="margin-top:10px;display: flex;">
                        <el-input style="width: 80px;margin-left: 10px;" placeholder="座位数" maxlength="2"
                            onkeyup="this.value = this.value.replace(/^(0+)|[^\d]+/g, '');"
                            v-model="find_data.needSeats">
                        </el-input>
                        <el-input style="width: 100px;margin-left: 10px;" placeholder="车牌号" maxlength="8"
                            v-model="find_data.plateNum">
                        </el-input>
                        <el-input style="width: 180px;margin-left: 10px;" placeholder="驾驶员姓名/手机号" maxlength="11"
                            v-model="find_data.driverName">
                        </el-input>
                        <el-input style="width: 180px;margin-left: 10px;" placeholder="乘车人姓名/手机号" maxlength="11"
                            v-model="find_data.cusName">
                        </el-input>
                        <el-input style="width: 180px;margin-left: 10px;" placeholder="下单人姓名/手机号" maxlength="11"
                            v-model="find_data.realName">
                        </el-input>
                        <el-select style="width:160px;margin-left: 20px;" v-model="find_data.companyNum"
                            placeholder="请选择抢单单位" clearable>
                            <el-option v-for="item in getCompanyCombo_list" :key="item.id" :label="item.company_name"
                                :value="item.company_num" />
                        </el-select>
                        <el-button style="margin-left: 20px;height:30px" @click="search_btn" type="primary"
                            icon="Search">搜索</el-button>
                    </div>


                    <!-- <el-input style="width: 160px;margin-left: 20px;" v-model="find_data.useCarCompanyId"
                        placeholder="请输入用车单位" clearable prefix-icon="Search" />
                    <el-input type="number" style="width: 140px;margin-left: 20px;" v-model="find_data.personNum"
                        placeholder="请输入人数" clearable prefix-icon="Search" />

                    <el-date-picker value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"
                        style="width: 180px;margin-left: 20px;" v-model="find_data.startTime" type="datetime"
                        placeholder="请选择用车时间" />

                    <el-input style="width: 160px;margin-left: 20px;" v-model="find_data.find" placeholder="请输入关键字"
                        clearable prefix-icon="Search" />
                    <el-input style="width: 170px;margin-left: 20px;" v-model="find_data.shareMobile"
                        placeholder="请输入推广人关键字" clearable prefix-icon="Search" />

                   -->


                </div>
                <!-- 功能按钮 -->
                <div style="margin-top:10px;">
                    <!-- <el-button @click="add_btn" type="primary" icon="SuccessFilled">添加</el-button>
                    <el-button @click="up_btn" type="warning" icon="WarnTriangleFilled">修改</el-button> -->
                    <el-button @click="del_btn" type="danger" icon="CircleCloseFilled">删除</el-button>
                    <!-- <el-button @click="mer_btn" type="success" icon="Finished">合并订单</el-button> -->
                    <!-- <el-button @click="nomer_btn" type="warning" icon="Finished">取消合并</el-button> -->
                    <el-button @click="out_btn" type="warning" icon="Share">导出</el-button>
                </div>
            </template>
            <div>
                <el-table border @selection-change="selection_change_btn" height="67vh" ref="multipleTableRef"
                    :data="list_data" style="width: 100%">
                    <el-table-column type="selection" width="35" />
                    <el-table-column label="编号" width="55" fixed type="index" />
                    <template v-for="item in table_data_list_new" :key="item.field">
                        <el-table-column v-if="item.off" :width="item.width" :prop="item.field" :label="item.label">
                            <template v-if="item.field == 'status'" #="{ row, column, $index }">

                                <!-- <span>
                                    {{ row.status == 'NOT_GRAB' ? '未抢单' : row.status == 'READY_CAR' ? '未派车' :
                        row.status
                            ==
                            'CAR_READY_CONFIRME' ? '待确认' : row.status == 'DRIVER_READY_RECEIVE' ? '师傅未确认' :
                            row.status ==
                                'DRIVER_CONFIRMED'
                                ? '师傅已确认' : row.status == 'START_TAKE_CUS' ? '出发去接客户' : row.status == 'ON_ROADING' ?
                                    '未完团' + ' ' + '【' + row.plateNum + '】' + ' ' + row.driverName + '-' +
                                    row.driverPhone :
                                    row.status == 'FINISHED' ? '完成' + ' ' + '【' + row.plateNum + '】' + ' ' +
                                        row.driverName
                                        + '-' + row.driverPhone : row.status == 'CANCELED' ? '已取消' : row.status == 'REFUSED'
                                            ?
                                            '已拒绝' : row.status == 'DELETE' ? '已删除' : '其他' }}
                                </span> -->
                                <span>
                                    {{ row.status == 'NOT_GRAB' ? '未抢单' : row.status == 'READY_CAR' ? '未派车' :
                        row.status
                            ==
                            'CAR_READY_CONFIRME' ? '未通知' : row.status == 'DRIVER_READY_RECEIVE' ? '师傅未确认' :
                            row.status ==
                                'DRIVER_CONFIRMED'
                                ? '师傅已确认' : row.status == 'START_TAKE_CUS' ? '出发去接客户' : row.status == 'ON_ROADING' ?
                                    '未完团' :
                                    row.status == 'FINISHED' ? '完成' : row.status == 'CANCELED' ? '已取消' : row.status ==
                                        'REFUSED'
                                        ?
                                        '已拒绝' : row.status == 'DELETE' ? '已删除' : '其他' }}
                                </span>



                            </template>
                            <template v-if="item.field == 'payWay'" #="{ row, column, $index }">
                                {{ row.payWay == 'WXPAY' ? '微信支付' : row.payWay == 'CASH' ? '现金支付' :
                        row.payWay == 'BALANCE' ? '全款已付' : row.payWay == 'ACCOUNTING' ? '记账' : '其他' }}
                            </template>

                            <!-- <template v-if="item.field == 'accidentList'" #="{ row, column, $index }">

                                <div v-if="row.accidentList">
                                    <el-button @click.native="accidentRecord_btn(row)" type="primary"
                                        size="small">异常报备</el-button>

                                </div>

                                <div v-else>
                                    无

                                </div>
                            </template> -->

                            <template v-if="item.field == 'plateNum'" #="{ row, column, $index }">
                                <span>{{ row.plateNum }}</span>

                            </template>

                            <template v-if="item.field == 'driverName'" #="{ row, column, $index }">
                                <span>{{ row.driverName ? row.driverName + '-' + row.driverPhone : '' }}</span>

                            </template>

                            <template v-if="item.field == 'pricealGathPrice'" #="{ row, column, $index }">
                                <span>{{ row.price - row.alGathPrice }}</span>
                            </template>
                            <template v-if="item.field == 'needSeats'" #="{ row, column, $index }">
                                <span>{{ row.needSeats ? row.needSeats + '座' : '不限车型' }}</span>
                            </template>
                            <template v-if="item.field == 'useCarCompanyId'" #="{ row, column, $index }">
                                <!-- row.realName ? row.realName  : -->
                                <span>{{
                        row.useCarCompanyName ? row.useCarCompanyName : row.mobile
                    }}{{ row.mobile ? '-' + row.mobile : '' }}</span>
                            </template>
                            <template v-if="item.field == 'useCarDutyInfo'" #="{ row, column, $index }">
                                <span>{{
                        row.useCarDutyInfo ? row.useCarDutyInfo.split('-').length > 2 ?
                            row.useCarDutyInfo.split('-')[1] + '-' + row.useCarDutyInfo.split('-')[2] :
                            row.useCarDutyInfo.split('-')[0] + '-' + row.useCarDutyInfo.split('-')[1]
                            : '' }}</span>
                            </template>
                            <template v-if="item.field == 'carDutyUserInfo'" #="{ row, column, $index }">
                                <span>{{
                        row.carDutyUserInfo ? row.carDutyUserInfo.split('-').length > 2 ?
                            row.carDutyUserInfo.split('-')[1] + '-' + row.carDutyUserInfo.split('-')[2] :
                            row.carDutyUserInfo.split('-')[0] + '-' + row.carDutyUserInfo.split('-')[1]
                            : '' }}</span>
                            </template>
                            <template v-if="item.field == 'cusName'" #="{ row, column, $index }">
                                <span>{{ row.cusName }}-{{ row.cusMobile }}</span>
                            </template>

                            <template v-if="item.field == 'startDate'" #="{ row, column, $index }">
                                <span>{{ row.startTime.split(' ')[0] }}</span>
                            </template>
                            <template v-if="item.field == 'persons'" #="{ row, column, $index }">
                                <span>{{ row.serviceMan ? row.serviceMan.split('-')[1] + '-' +
                        row.serviceMan.split('-')[2]
                        : '' }}</span>
                            </template>

                            <template v-if="item.field == 'startTime'" #="{ row, column, $index }">
                                <span>{{ row.startTime.split(' ')[1] }}</span>
                            </template>

                            <template v-if="item.field == 'endDate'" #="{ row, column, $index }">
                                <span>{{ row.endTime.split(' ')[0] }}</span>
                            </template>

                            <template v-if="item.field == 'endTime'" #="{ row, column, $index }">
                                <span>{{ row.endTime.split(' ')[1] }}</span>
                            </template>
                            <template v-if="item.field == 'CompanylInfo'" #="{ row, column, $index }">
                                <span>{{ row.companyNum }} {{ row.companyInfo ? '-' + row.companyInfo : '' }}</span>
                            </template>

                        </el-table-column>
                    </template>
                </el-table>
            </div>

            <div style="margin-top:20px">
                <el-pagination @current-change="current_change_btn" @size-change="size_change_btn"
                    v-model:current-page="find_data.page.pageNum" v-model:page-size="find_data.page.pageSize"
                    :page-sizes="[20, 50, 100, 200]" :background="true"
                    layout="prev, pager, next, jumper,->,sizes,total," :total="total" />
            </div>
        </el-card>
    </div>

    <!-- 弹窗 -->
    <div>
        <!-- 表格筛选 -->
        <div style="position: absolute;top:75px;z-index: 2;" :style="icon_off ? 'right:0px;' : 'right:110px;'">
            <el-icon @click="icon_btn" :size="20">
                <Setting />
            </el-icon>
            <div v-show="icon_off"
                style=" position: relative;top:-100px;right:140px;width: 130px;height:430px;background:#fff;overflow: hidden;">
                <div class="cols-set" style="background:#fff;width:90%;height:97%;margin:auto;margin-top:10px;">
                    <div>
                        <el-button-group style="display: flex; ">
                            <el-tooltip effect="dark" placement="bottom">
                                <template #content>注意：拖动下面的项，可以改变表格列的顺序，<br />记得点击保存才会永久生效哦！ </template>
                                <el-button style="width:10px" type="primary" icon="WarningFilled"></el-button>
                            </el-tooltip>
                            <el-button title="重置" type="primary" icon="Refresh" @click="resetTableSet"></el-button>
                            <el-button title="保存" type="primary" icon="Check" @click="saveTableSet"></el-button>
                        </el-button-group>
                        <div ref="sortableContainer" class="col-items" style="height:400px; overflow-y: auto; ">
                            <el-checkbox class="drag_it" @change="checkbox_btn" v-for="item in sortedItems"
                                :key="item.field" v-model="item.off" :label="item.label" border>
                            </el-checkbox>
                        </div>

                    </div>
                </div>
            </div>
        </div>
        <!-- 添加修改 -->
        <el-dialog style="margin-top:5vh" v-model="add_off" :title="title"
            :width="add_data.isReturnAdd == 'true' || add_data.isReturnAdd == '是' ? '100%' : '50%'"
            :close-on-click-modal='false'>
            <div style="display: flex;">
                <div :style="add_data.isReturnAdd == 'true' || add_data.isReturnAdd == '是' ? 'width:48%' : ''">
                    <div style="color:red;">系统默认拼车时间30分钟：系统自动按照当前出发时间前后30分钟可拼订单自动拼单！
                    </div>
                    <el-tabs v-model="add_data.routeSimpleName" class="demo-tabs" @tab-click="handleClick">
                        <el-tab-pane label="拼车接天府" name="拼车接天府">
                            <el-form :model="add_data" label-width="110px" label-suffix="：">

                                <div style="display:flex;">
                                    <el-button @click="land_se_btn" style="margin-left:20px"
                                        type="primary">航班号自动查询</el-button>
                                    <el-form-item label="接机时间" :required="false">
                                        <el-date-picker style=" width: 160px" value-format="YYYY-MM-DD HH:mm"
                                            format="YYYY-MM-DD HH:mm" v-model="add_data.landDate" type="datetime"
                                            placeholder="请选择接机时间" />
                                    </el-form-item>


                                </div>
                                <div style="display:flex;">
                                    <!-- <el-form-item label="目的地址" :required="false">
                                    <el-autocomplete v-model="add_data.toLocation" :fetch-suggestions="toLocation_querySearch"
                                        :trigger-on-focus="false" clearable class="inline-input w-50" placeholder="请输入目的地址"
                                        @select="toLocation_handleSelect" />
                                </el-form-item> -->
                                    <el-form-item label="接机地点" :required="false">
                                        <el-select style="width:150px" v-model="add_data.fromLocation"
                                            placeholder="请选择接机地点" clearable>
                                            <el-option v-for="item in fromLocation_list" :key="item.value"
                                                :label="item.label" :value="item.value" />
                                        </el-select>
                                    </el-form-item>
                                    <el-form-item label="目的地址" :required="false">
                                        <el-select @change="select_Btn" v-model="add_data.toLocation" class="m-2"
                                            placeholder="请选择目的地址" size="large">
                                            <el-option v-for="item in getStationList_Data" :key="item.stationName"
                                                :label="item.stationName" :value="item.stationName" />
                                        </el-select>
                                    </el-form-item>
                                    <el-button @click="map_off_btn" style="margin-left:30px;margin-bottom:10px"
                                        type="primary">地图选址</el-button>
                                </div>
                                <el-form-item type="number" label="预约人数" :required="false">
                                    <el-input v-model="add_data.personNum" placeholder="请输入预约人数" />
                                </el-form-item>
                                <el-form-item label="联系人姓名" :required="false">
                                    <el-input v-model="add_data.cusName" placeholder="请输入联系人姓名" />
                                </el-form-item>
                                <el-form-item type="number" label="联系人电话" :required="false">
                                    <el-input v-model="add_data.cusMobile" placeholder="请输入联系人电话" />
                                </el-form-item>
                                <el-form-item label="是否返程" :required="false">
                                    <el-select @change="isReturnAdd_change" style="width:180px"
                                        v-model="add_data.isReturnAdd" placeholder="请选择是否返程" clearable>
                                        <el-option v-for="item in isReturn_list" :key="item.value" :label="item.label"
                                            :value="item.value" />
                                    </el-select>
                                </el-form-item>
                                <el-collapse>
                                    <el-collapse-item title="显示更多选填信息" name="1">
                                        <!-- <el-form-item type="number" label="行李箱数" :required="false">
                                        <el-input v-model="add_data.cusMobile" placeholder="请输入行李箱数" />
                                    </el-form-item> -->
                                        <!-- <el-form-item type="number" label="感谢费" :required="false">
                                        <el-input v-model="add_data.cusMobile" placeholder="请输入感谢费" />
                                    </el-form-item> -->
                                        <!-- <el-form-item label="返程时间" :required="false">
                                            <el-date-picker value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"
                                                style="width: 180px;" v-model="add_data.returnTime" type="datetime"
                                                placeholder="请选择时间" /> -->

                                        <!-- </el-form-item> -->
                                        <el-form-item label="备注" :required="false">
                                            <el-input show-word-limit maxlength="200" :rows="4" type="textarea"
                                                placeholder="请输入备注" v-model="add_data.remark" />
                                        </el-form-item>
                                    </el-collapse-item>

                                </el-collapse>

                            </el-form>
                        </el-tab-pane>
                        <el-tab-pane label="拼车送天府" name="拼车送天府">
                            <el-form :model="add_data" label-width="110px" label-suffix="：">

                                <div style="display:flex;">
                                    <el-button @click="land_se_btn" style="margin-left:20px"
                                        type="primary">航班号自动查询</el-button>
                                    <el-form-item label="送机时间" :required="false">
                                        <el-date-picker style=" width: 160px" value-format="YYYY-MM-DD HH:mm"
                                            format="YYYY-MM-DD HH:mm" v-model="add_data.flightDate" type="datetime"
                                            placeholder="请选择送机时间" />
                                    </el-form-item>


                                </div>
                                <div style="display:flex;">
                                    <!-- <el-form-item label="接人地址" :required="false">
                                    <el-autocomplete v-model="add_data.fromLocation" :fetch-suggestions="toLocation_querySearch"
                                        :trigger-on-focus="false" clearable class="inline-input w-50" placeholder="请输入接人地址"
                                        @select="toLocation_handleSelect" />
                                </el-form-item> -->
                                    <el-form-item label="接人地址" :required="false">
                                        <el-select @change="select_Btn" v-model="add_data.fromLocation" class="m-2"
                                            placeholder="请输入接人地址" size="large">
                                            <el-option v-for="item in getStationList_Data" :key="item.stationName"
                                                :label="item.stationName" :value="item.stationName" />
                                        </el-select>
                                    </el-form-item>
                                    <el-button @click="map_off_btn" style="margin-left:30px;margin-bottom:10px"
                                        type="primary">地图选址</el-button>
                                    <el-form-item label="送机地点" :required="false">
                                        <el-select style="width:150px" v-model="add_data.toLocation"
                                            placeholder="请选择送机地点" clearable>
                                            <el-option v-for="item in fromLocation_list" :key="item.value"
                                                :label="item.label" :value="item.value" />
                                        </el-select>
                                    </el-form-item>

                                </div>

                                <el-form-item type="number" label="预约人数" :required="false">
                                    <el-input v-model="add_data.personNum" placeholder="请输入预约人数" />
                                </el-form-item>
                                <el-form-item label="联系人姓名" :required="false">
                                    <el-input v-model="add_data.cusName" placeholder="请输入联系人姓名" />
                                </el-form-item>
                                <el-form-item type="number" label="联系人电话" :required="false">
                                    <el-input v-model="add_data.cusMobile" placeholder="请输入联系人电话" />
                                </el-form-item>
                                <el-form-item label="是否返程" :required="false">
                                    <el-select @change="isReturnAdd_change" style="width:180px"
                                        v-model="add_data.isReturnAdd" placeholder="请选择是否返程" clearable>
                                        <el-option v-for="item in isReturn_list" :key="item.value" :label="item.label"
                                            :value="item.value" />
                                    </el-select>
                                </el-form-item>
                                <el-collapse>
                                    <el-collapse-item title="显示更多选填信息" name="1">
                                        <!-- <el-form-item type="number" label="行李箱数" :required="false">
                                        <el-input v-model="add_data.cusMobile" placeholder="请输入行李箱数" />
                                    </el-form-item> -->
                                        <!-- <el-form-item type="number" label="感谢费" :required="false">
                                        <el-input v-model="add_data.cusMobile" placeholder="请输入感谢费" />
                                    </el-form-item> -->
                                        <!-- <el-form-item label="返程时间" :required="false">
                                            <el-date-picker value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"
                                                style="width: 180px;" v-model="add_data.returnTime" type="datetime"
                                                placeholder="请选择时间" />

                                        </el-form-item> -->
                                        <el-form-item label="备注" :required="false">
                                            <el-input show-word-limit maxlength="200" :rows="4" type="textarea"
                                                placeholder="请输入备注" v-model="add_data.remark" />
                                        </el-form-item>
                                    </el-collapse-item>

                                </el-collapse>

                            </el-form>
                        </el-tab-pane>
                    </el-tabs>

                    <el-button @click="ok_btn" style="margin-left:40vw;margin-top:10px" type="primary">确认提交</el-button>
                </div>
                <el-divider v-if="add_data.isReturnAdd == 'true' || add_data.isReturnAdd == '是'" style="height:70vh;"
                    direction="vertical" />
                <div style="margin-left:20px" v-if="add_data.isReturnAdd == 'true' || add_data.isReturnAdd == '是'"
                    :style="add_data.isReturnAdd == 'true' || add_data.isReturnAdd == '是' ? 'width:48%' : ''">
                    <div style="font-size:20px;font-weight:700;">返程信息: <text
                            style="font-size:20px;font-weight:700;color:red ;">
                            {{ add_data.routeSimpleName == '拼车接天府' ? '拼车送天府' : '拼车接天府' }}</text></div>

                    <div style="margin-top:40px;">
                        <!-- 接机返程 -->
                        <div v-if="add_data.routeSimpleName == '拼车接天府'">
                            <el-form :model="add_data" label-width="110px" label-suffix="：">

                                <div style="display:flex;">
                                    <el-button @click="land_se_btn(2)" style="margin-left:20px"
                                        type="primary">航班号自动查询</el-button>
                                    <el-form-item label="送机时间" :required="false">
                                        <el-date-picker style=" width: 160px" value-format="YYYY-MM-DD HH:mm"
                                            format="YYYY-MM-DD HH:mm" v-model="add_data.returnOrder.flightDate"
                                            type="datetime" placeholder="请选择送机时间" />
                                    </el-form-item>


                                </div>
                                <div style="display:flex;">
                                    <!-- <el-form-item label="接人地址" :required="false">
                                    <el-autocomplete v-model="add_data.fromLocation" :fetch-suggestions="toLocation_querySearch"
                                        :trigger-on-focus="false" clearable class="inline-input w-50" placeholder="请输入接人地址"
                                        @select="toLocation_handleSelect" />
                                </el-form-item> -->
                                    <el-form-item label="接人地址" :required="false">
                                        <el-select @change="select_Btn2" v-model="add_data.returnOrder.fromLocation"
                                            class="m-2" placeholder="请输入接人地址" size="large">
                                            <el-option v-for="item in getStationList_Data" :key="item.stationName"
                                                :label="item.stationName" :value="item.stationName" />
                                        </el-select>
                                    </el-form-item>
                                    <el-button @click="map_off_btn(2)" style="margin-left:30px;margin-bottom:10px"
                                        type="primary">地图选址</el-button>
                                    <el-form-item label="送机地点" :required="false">
                                        <el-select style="width:150px" v-model="add_data.returnOrder.toLocation"
                                            placeholder="请选择送机地点" clearable>
                                            <el-option v-for="item in fromLocation_list" :key="item.value"
                                                :label="item.label" :value="item.value" />
                                        </el-select>
                                    </el-form-item>

                                </div>

                                <el-form-item type="number" label="预约人数" :required="false">
                                    <el-input v-model="add_data.returnOrder.personNum" placeholder="请输入预约人数" />
                                </el-form-item>
                                <el-form-item label="联系人姓名" :required="false">
                                    <el-input v-model="add_data.returnOrder.cusName" placeholder="请输入联系人姓名" />
                                </el-form-item>
                                <el-form-item type="number" label="联系人电话" :required="false">
                                    <el-input v-model="add_data.returnOrder.cusMobile" placeholder="请输入联系人电话" />
                                </el-form-item>

                            </el-form>
                            <el-collapse>
                                <el-collapse-item title="显示更多选填信息" name="1">

                                    <el-form-item label="备注" :required="false">
                                        <el-input show-word-limit maxlength="200" :rows="4" type="textarea"
                                            placeholder="请输入备注" v-model="add_data.returnOrder.remark" />
                                    </el-form-item>
                                </el-collapse-item>

                            </el-collapse>
                        </div>
                        <!-- 送机返程 -->
                        <div v-if="add_data.routeSimpleName == '拼车送天府'">
                            <el-form :model="add_data" label-width="110px" label-suffix="：">

                                <div style="display:flex;">
                                    <el-button @click="land_se_btn(2)" style="margin-left:20px"
                                        type="primary">航班号自动查询</el-button>
                                    <el-form-item label="接机时间" :required="false">
                                        <el-date-picker style=" width: 160px" value-format="YYYY-MM-DD HH:mm"
                                            format="YYYY-MM-DD HH:mm" v-model="add_data.returnOrder.landDate"
                                            type="datetime" placeholder="请选择接机时间" />
                                    </el-form-item>


                                </div>
                                <div style="display:flex;">
                                    <!-- <el-form-item label="目的地址" :required="false">
                                    <el-autocomplete v-model="add_data.toLocation" :fetch-suggestions="toLocation_querySearch"
                                        :trigger-on-focus="false" clearable class="inline-input w-50" placeholder="请输入目的地址"
                                        @select="toLocation_handleSelect" />
                                </el-form-item> -->
                                    <el-form-item label="接机地点" :required="false">
                                        <el-select style="width:150px" v-model="add_data.returnOrder.fromLocation"
                                            placeholder="请选择接机地点" clearable>
                                            <el-option v-for="item in fromLocation_list" :key="item.value"
                                                :label="item.label" :value="item.value" />
                                        </el-select>
                                    </el-form-item>
                                    <el-form-item label="目的地址" :required="false">
                                        <el-select @change="select_Btn2" v-model="add_data.returnOrder.toLocation"
                                            class="m-2" placeholder="请选择目的地址" size="large">
                                            <el-option v-for="item in getStationList_Data" :key="item.stationName"
                                                :label="item.stationName" :value="item.stationName" />
                                        </el-select>
                                    </el-form-item>
                                    <el-button @click="map_off_btn(2)" style="margin-left:30px;margin-bottom:10px"
                                        type="primary">地图选址</el-button>
                                </div>
                                <el-form-item type="number" label="预约人数" :required="false">
                                    <el-input v-model="add_data.returnOrder.personNum" placeholder="请输入预约人数" />
                                </el-form-item>

                                <el-form-item label="联系人姓名" :required="false">
                                    <el-input v-model="add_data.returnOrder.cusName" placeholder="请输入联系人姓名" />
                                </el-form-item>
                                <el-form-item type="number" label="联系人电话" :required="false">
                                    <el-input v-model="add_data.returnOrder.cusMobile" placeholder="请输入联系人电话" />
                                </el-form-item>
                            </el-form>
                            <el-collapse>
                                <el-collapse-item title="显示更多选填信息" name="1">

                                    <el-form-item label="备注" :required="false">
                                        <el-input show-word-limit maxlength="200" :rows="4" type="textarea"
                                            placeholder="请输入备注" v-model="add_data.returnOrder.remark" />
                                    </el-form-item>
                                </el-collapse-item>

                            </el-collapse>
                        </div>
                    </div>
                </div>
            </div>
        </el-dialog>
        <!-- 地图弹窗 -->
        <el-dialog style="margin-top:10vh;height:80vh;overflow: hidden;" v-model="map_off" title="酒店地址:" width="80%"
            :close-on-click-modal='false'>
            <div class="div_map">
                <div class="map_input">
                    <el-input @input="map_change" id='tipinput' style="width:40%" v-model="map_address"
                        placeholder="请输入酒店地址">
                        <template #prepend>酒店地址:</template>
                    </el-input>
                    <el-button @click="map_ok_btn" type="primary">确认</el-button>
                </div>
                <div v-if="map_address_list.length > 0" class="map_input2">
                    <div style="width:40%;background:#fff;margin-left:20px;padding: 10px;font-weight: 700;">
                        <div @click="map_list_btn(item)" class="div_bg" v-for="(item, index) in map_address_list"
                            :key="index" style="margin-top: 10px;">
                            {{ item.district }}-{{ item.address }}-{{ item.name }}
                        </div>
                    </div>
                </div>
                <div id="myMap" style="height: 65vh; width: 100%">
                </div>
            </div>
        </el-dialog>

        <!-- 航班选择 -->
        <el-dialog style="margin-top:5vh" v-model="land_se_off" title="航班自动查询" width="40%"
            :close-on-click-modal='false'>
            <div>
                <div style="color:red">
                    航班自动查询：【接天府】航班降落时间系统会默认延后30分钟
                </div>
                <div style="color:red;margin-top:10px">
                    航班自动查询：【送天府】航班起飞时间系统会默认提前4小时
                </div>
                <div style="margin-top:20px">
                    <el-form :model="land_se" label-width="110px" label-suffix="：">

                        <el-form-item label="航班号" :required="false">
                            <el-input style=" width: 200px" v-model="land_se.num" placeholder="请输入航班号" />
                        </el-form-item>
                        <el-form-item label="航班日期" :required="false">
                            <el-date-picker style=" width: 200px" value-format="YYYY-MM-DD" format="YYYY-MM-DD"
                                v-model="land_se.date" type="date" placeholder="请选择航班日期" />
                        </el-form-item>
                        <el-button @click="ok_land_se_btn" style="margin-left:30vw;margin-top:5px"
                            type="primary">确认查询</el-button>
                        <hr>
                        <div v-if="land_se_list.depPort" style="width: 80%;display:flex;;border-radius: 8px;background: antiquewhite;margin: auto;height: 80px;
                        justify-content: space-evenly; " @click="land_se_list_btn(1)">
                            <div style="display: flex;flex-direction: column;justify-content: space-evenly;">
                                <div style="font-weight:700">{{ land_se_list.depScheduled.split(' ')[1] }}</div>
                                <div>{{ land_se_list.depPort }}T{{ land_se_list.depTerminal }}</div>
                                <div style="color:#666;font-weight:700"> {{ land_se_list.flightNo }}</div>
                            </div>
                            <div style="display:flex;align-items: center;">
                                <el-icon :size="60">
                                    <DArrowRight />
                                </el-icon>
                            </div>
                            <div style="display: flex;flex-direction: column;justify-content: space-evenly;">
                                <div style="font-weight:700"> {{ land_se_list.arrScheduled.split(' ')[1] }}</div>
                                <div> {{ land_se_list.arrPort }}T{{ land_se_list.arrTerminal }}</div>
                                <div style="color:#666;font-weight:700"> {{ land_se_list.depScheduled.split(' ')[0] }}
                                </div>
                            </div>
                        </div>
                    </el-form>
                </div>
            </div>


        </el-dialog>

        <!-- 订单合并-->
        <el-dialog style="margin-top:5vh" v-model="mer_off" title="合并订单" width="80%" :close-on-click-modal='false'>
            <div>

                <el-table border @selection-change="table_list_selection_change_btn" height="60vh"
                    ref="multipleTableRef" :data="mer_list" style="width: 100%">
                    <el-table-column type="selection" width="35" />
                    <el-table-column label="编号" width="55" fixed type="index" />
                    <el-table-column width="120" property="orderNum" label="订单号" />
                    <el-table-column width="120" property="routeSimpleName" label="行程简称" />
                    <el-table-column width="100" label="订单状态">
                        <template #="{ row, column, $index }">
                            {{ row.status == 'READY_CAR' ? '未派车' : row.status == 'CAR_READY_CONFIRME' ? '待确认' :
                        row.status
                            ==
                            'DRIVER_READY_RECEIVE' ? '待接单' : row.status == 'READY_ROAD' ? '未出行' : row.status ==
                                'ON_ROADING'
                                ? '未完团' : row.status == 'FINISHED' ? '完成' : '' }}

                        </template>
                    </el-table-column>
                    <el-table-column width="120" property="personNum" label="人数" />
                    <el-table-column width="120" property="flightNum" label="航班号" />
                    <el-table-column width="120" label="出发日期">
                        <template #="{ row, column, $index }">
                            <span>{{ row.startTime.split(' ')[0] }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column width="100" label="出发时间">
                        <template #="{ row, column, $index }">
                            <span>{{ row.startTime.split(' ')[1] }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column width="120" property="waitDate" label="可等待时间" />
                    <el-table-column width="220" property="fromLocation" label="起点" />
                    <el-table-column width="220" property="toLocation" label="终点" />
                    <el-table-column width="160" label="乘车人">
                        <template #="{ row, column, $index }">
                            <span>{{ row.cusName }}-{{ row.cusMobile }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column width="100" label="推广人">
                        <template #="{ row, column, $index }">
                            <span v-if="row.shareName">{{ row.shareName }}-{{ row.shareMobile }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column width="100" property="price" label="订单价格" />
                    <el-table-column width="220" property="remark" label="客户备注" />
                    <el-table-column width="120" property="useCarCompanyId" label="用车单位" />
                    <el-table-column width="120" property="useCarName" label="用车负责人 " />
                    <el-table-column width="170" property="addTime" label="添加时间" />
                    <el-table-column width="120" property="isMerge" label="合并标识" />
                    <el-table-column width="100" label="合并标识">
                        <template #="{ row, column, $index }">
                            <span>{{ row.isMerge == true ? '合并' : '未合并' }}</span>
                        </template>
                    </el-table-column>
                </el-table>
                <el-button style="margin-left:67vw;margin-top:20px;" @click="mer_add_ok_btn"
                    type="primary">确认合并</el-button>
            </div>


        </el-dialog>
    </div>
</template>

<script setup>
import Sortable from 'sortablejs';
import { ref, reactive, onMounted, computed } from 'vue'
import {
    getServiceMans, findComboCusList, getCompanyCombo,
    getOrderList, findTravelWayInfo, getStationListPages, add,
    edit, omsorderdelete, getOrderInfo, mergeQuery, merge, omsorderexport, cancelMerge, adupPrivateSet, getPrivateSetList
} from '@/api/order_list.js'
import { ElMessage, ElLoading, ElMessageBox } from 'element-plus'
import AMapLoader from "@amap/amap-jsapi-loader"
import { securityJsCode, key } from '@/utils/common.js'
import * as XLSX from 'xlsx';
import CircularJSON from 'circular-json'
onMounted(async () => {

    getPrivateSetList({
        find: '原始订单列表',
        page: {
            pageNum: 1,
            pageSize: 999,
        },
    }).then(res => {
        if (res.data.list[0]) {
            table_data_list_new.value = JSON.parse(res.data.list[res.data.list.length - 1].dat)
        } else {
            table_data_list_new.value = table_data_list
        }
    })
    getServiceMans({

    }).then(res => {
        if (res.code == 1) {
            getServiceMans_list.value = res.data;

        }
    })
    getCompanyCombo({

    }).then(res => {
        if (res.code == 1) {
            getCompanyCombo_list.value = res.data

        }
    })

    findComboCusList({
        page: {
            pageNum: 1,
            pageSize: 999,
        },



    }).then(res => {
        findComboCusList_list_yongche.value = res.data.list
        findComboCusList_list_yongche2.value = res.data.list
    })

    Sortable.create(sortableContainer.value, {
        draggable: '.drag_it',
        ghostClass: 'sortable-ghost',
        onEnd: evt => {
            const targetRow = table_data_list_new.value.splice(evt.oldIndex, 1)[0];
            table_data_list_new.value.splice(evt.newIndex, 0, targetRow);

            // 重新赋值给列数组
            // let cols = that.U.scopy(that.fields);
            // let list = cols.filter(it => { return it.show; });
            // that.$emit('saveSet', {dgName: that.dgName, cols: list});
        }
    })
    timeTypeTime.value = [new_day(), to_day()]
    find_data.stime = new_day()
    find_data.etime = to_day()
    await getStationList()
    await list_api()
})
const payWay_List = ref([
    { id: "WXPAY", name: "微信支付" },
    { id: "CASH", name: "现金支付" },
    { id: "BALANCE ", name: "余额支付" },
    { id: "ACCOUNTING ", name: "记账" },

])
const getCompanyCombo_list = ref([])
const findComboCusList_list_yongche = ref([])
const findComboCusList_list_yongche2 = ref([])
const dutyService_list = ref([])
const findComboCusList_list_handleFilter = (value) => {
    // 自定义筛选逻辑
    if (value) {
        let results = findComboCusList_list_yongche2.value.filter(item => {
            for (let key in item) {
                if (typeof item[key] === 'string' && item[key].includes(value)) {
                    return true;
                }
            }
            return false;
        })
        if (results.length > 0) {
            findComboCusList_list_yongche.value = results
        } else {
            findComboCusList_list_yongche.value = []
        }
    } else {
        findComboCusList_list_yongche.value = findComboCusList_list_yongche2.value
    }
}

const cusCompanySimpleName_change = (e) => {
    for (let i = 0; i < findComboCusList_list_yongche2.value.length; i++) {
        if (e == findComboCusList_list_yongche2.value[i].id) {
            let data = findComboCusList_list_yongche2.value[i].dutyService.split(',')
            dutyService_list.value = []
            console.log(data)

            for (let j = 0; j < data.length; j++) {
                let obj = {}
                obj.id = data[j].split('-')[0]
                obj.name = data[j].split('-')[1]
                obj.phone = data[j].split('-')[2]
                dutyService_list.value.push(obj)
            }
        }
    }
}
const orderStates = ref([
    { id: "READY_CAR", name: "未派车" },
    { id: "CAR_READY_CONFIRME", name: "未通知" },
    { id: "DRIVER_READY_RECEIVE", name: "已通知" },
    { id: "DRIVER_CONFIRMED", name: "师傅已确认" },
    { id: "ON_ROADING", name: "已出行" },
    { id: "FINISHED", name: "已完成" },
    { id: "CANCELED", name: "已取消" },
    { id: "REFUSED", name: "已拒绝" },
    { id: "START_TAKE_CUS", name: "出发去接客户" },
    { id: "DELETE", name: "已删除" },
    //     { id: "PENDING", name: "已待定" },
    //     { id: "GRAB_SUCCESS", name: "抢单成功" },
    //     { id: "TRANS_SUCCESS", name: "转接成功" },

])
//#region 表格数据处理
const table_data_list = reactive([
    { label: '行程简称', field: 'routeSimpleName', width: 150, off: true },


    { label: "订单状态", field: "status", width: 120, off: true },
    { label: "支付方式", field: "payWay", width: 120, off: true },
    { label: "车型", field: "needSeats", width: 90, off: true },
    { label: "已派车辆", field: "plateNum", width: 125, off: true },
    { label: "驾驶员", field: "driverName", width: 185, off: true },
    { label: "人数", field: "personNum", width: 60, off: true },
    { label: "抢单单位", field: "CompanylInfo", width: 220, off: true },
    { label: '订单价格', field: 'price', width: 100, off: true },
    { label: "保障用车", field: "ensureMoney", width: 100, off: true },
    { label: "指定用车", field: "regularCarMoney ", width: 100, off: true },
    { label: '夜班费', field: 'nightMoney', width: 100, off: true },
    { label: '巴士币', field: 'pointMoney', width: 100, off: true },
    { label: '途经店费用', field: 'pathWayMoney', width: 100, off: true },
    { label: '应付余额', field: 'pricealGathPrice', width: 100, off: true },
    { label: "合并标记", field: "groupNum", width: 90, off: true },
    { label: '行程详情', field: 'details', width: 700, off: true },
    { label: '客户', field: 'cusName', width: 160, off: true },
    { label: '客户备注', field: 'remark', width: 700, off: true },
    { label: '业务员备注', field: 'serviceManRemark', width: 220, off: true },
    { label: "异常报备", field: "accidentList", width: 100, off: true },
    { label: '订单号', field: 'orderNum', width: 130, off: true },
    { label: "支付单号", field: "payOrderNum", width: 220, off: true },
    { label: '业务员', field: 'persons', width: 160, off: true },
    { label: '航班车次', field: 'flightNum', width: 120, off: true },
    { label: '用车单位', field: 'useCarCompanyId', width: 220, off: true },
    { label: '用车负责人', field: 'useCarDutyInfo', width: 220, off: true },
    { label: '供车单位', field: 'carCompanyName', width: 220, off: true },
    { label: '供车负责人', field: 'carDutyUserInfo', width: 220, off: true },
    { label: '出发日期', field: 'startDate', width: 120, off: true },
    { label: '出发时间', field: 'startTime', width: 100, off: true },
    { label: '到达日期', field: 'endDate', width: 120, off: true },
    { label: '到达时间', field: 'endTime', width: 100, off: true },
    { label: '添加时间', field: 'addTime', width: 175, off: true },





])

const table_data_list_new = ref([])
const icon_off = ref(false)
// 创建排序容器的引用
const sortableContainer = ref('')

const icon_btn = () => {
    icon_off.value = !icon_off.value
    console.log(sortableContainer.value)

}
const resetTableSet = () => {
    console.log(table_data_list)
    table_data_list_new.value = JSON.parse(JSON.stringify(table_data_list))
    console.log(table_data_list)
    console.log(table_data_list_new.value)
}
const saveTableSet = () => {
    adupPrivateSet({
        dat: JSON.stringify(table_data_list_new.value),
        tbName: '原始订单列表',
        tbNum: "original_order_list",
    }).then(res => {
        if (res.code == 1) {
            return ElMessage({
                message: res.msg,
                type: 'success',
            })
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })
    icon_off.value = false
}

const checkbox_btn = (e, c) => {
    for (let i = 0; i < table_data_list_new.value.length; i++) {
        if (table_data_list_new.value[i].label == c.target._value) {
            table_data_list_new.value[i].off == e

        }

    }

}

const sortedItems = computed(() => {
    return [...table_data_list_new.value].sort((a, b) => a.id - b.id);
})
//#endregion


//#region 订单合并
const mer_off = ref(false)
const mer_list = ref([])
//订单合并表格选择
const table_list_table_list = ref([])
const table_list_selection_change_btn = (e) => {
    table_list_table_list.value = e
    console.log(table_list_table_list.value)
}

const mer_btn = () => {
    if (table_list.value.length != 1) {
        return ElMessage({
            message: '请选择一条数据！',
            type: 'warning',
        })
    }
    //87  table_list.value[0].id
    mergeQuery({ id: table_list.value[0].id }).then(res => {
        if (res.code == 1) {
            mer_list.value = res.data
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })

    mer_off.value = true
}
const mer_add_ok_btn = () => {
    if (table_list_table_list.value.length > 2 || table_list_table_list.value.length < 1) {

        return ElMessage({
            message: '请选择一条或两条数据进行合并！',
            type: 'warning',
        })
    }
    let ps = [table_list.value[0].id]
    for (let i = 0; i < table_list_table_list.value.length; i++) {
        ps.push(table_list_table_list.value[i].id)
    }
    merge({ ids: ps }).then(res => {
        if (res.code == 1) {
            list_api()
            mer_off.value = false
            return ElMessage({
                message: res.msg,
                type: 'success',
            })
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })
}
//#endregion
//#region 取消合并
const nomer_btn = () => {
    if (table_list.value.length != 1) {

        return ElMessage({
            message: '请选择一条数据取消合并！',
            type: 'warning',
        })
    }
    // 115  table_list.value[0].id
    cancelMerge({ id: table_list.value[0].id }).then(res => {
        if (res.code == 1) {
            list_api()
            return ElMessage({
                message: res.msg,
                type: 'success',
            })
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })
}
//#endregion
// 是否返程
const new_day = () => {
    let today = new Date();

    let year = today.getFullYear();
    let month = today.getMonth() + 1; // 月份是从 0 到 11，所以需要加上 1
    let day = today.getDate();

    // 如果月份或日期小于 10，则在前面补零
    if (month < 10) {
        month = '0' + month;
    }

    if (day < 10) {
        day = '0' + day;
    }

    let formattedDate = `${year}-${month}-${day} 00:00:00`;
    return formattedDate
}
const to_day = () => {
    let today = new Date();
    let tomorrow = new Date(today);
    tomorrow.setDate(tomorrow.getDate() + 1);

    let year = tomorrow.getFullYear();
    let month = tomorrow.getMonth() + 1; // 月份是从 0 到 11，所以需要加上 1
    let day = tomorrow.getDate();

    // 如果月份或日期小于 10，则在前面补零
    if (month < 10) {
        month = '0' + month;
    }

    if (day < 10) {
        day = '0' + day;
    }

    let formattedDate = `${year}-${month}-${day} 23:59:59`;
    return formattedDate
}
const defaultTime = [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]
const timeTypeTime = ref([])
const timeTypeTime_btn = (e) => {
    if (e) {
        timeTypeTime.value = e
        find_data.stime = timeTypeTime.value[0]
        find_data.etime = timeTypeTime.value[1]
        find_data.timeType = '0'
    } else {
        timeTypeTime.value = ''
        find_data.stime = ''
        find_data.etime = ''
        find_data.timeType = ''
    }
}
const isReturn_map_off = ref('')
const isReturn_list = reactive([
    {
        value: 'true',
        label: '是',
    },
    {
        value: 'false',
        label: '否',
    },
])

// 行程简章
const routeSimpleName_list = reactive([
    {
        value: '送天府',
        label: '送天府',
    },
    {
        value: '接天府',
        label: '接天府',
    },
    {
        value: '拼车送天府',
        label: '拼车送天府',
    },
    {
        value: '拼车接天府',
        label: '拼车接天府',
    },
    {
        value: '送双流',
        label: '送双流',
    },
    {
        value: '接双流',
        label: '接双流',
    },
    {
        value: '送东站',
        label: '送东站',
    },
    {
        value: '接东站',
        label: '接东站',
    },
    {
        value: '送西站',
        label: '送西站',
    },
    {
        value: '接西站',
        label: '接西站',
    },
    {
        value: '送南站',
        label: '送南站',
    },
    {
        value: '接南站',
        label: '接南站',
    }, {
        value: '送集合点大巴',
        label: '送集合点大巴',
    },
    {
        value: '接集合点大巴',
        label: '接集合点大巴',
    },
])

//#region 航班查询
const land_se_off = ref(false)
const land_se = reactive({
    date: '',
    num: '',
    travelWay: '1'
})
const land_se_btn_num = ref('1')
const land_se_btn = (e) => {
    if (e == 2) {
        land_se.date = ''
        land_se.num = ''
        land_se_list.value = {}
        land_se_btn_num.value = '2'
        land_se_off.value = true
    } else {
        land_se.date = ''
        land_se.num = ''
        land_se_list.value = {}
        land_se_btn_num.value = '1'
        land_se_off.value = true
    }
}
const land_se_list = ref({})

const ok_land_se_btn = () => {
    if (!land_se.date) {
        return ElMessage({
            message: '请输入航班时间',
            type: 'warning',
        })
    } else if (!land_se.num) {
        return ElMessage({
            message: '请输入航班号',
            type: 'warning',
        })
    }

    findTravelWayInfo(land_se).then(res => {
        if (res.code == 1) {
            land_se_list.value = res.data.data.list[0]
            return ElMessage({
                message: res.msg,
                type: 'success',
            })
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })
}
const land_se_list_btn = (e) => {
    if (land_se_btn_num.value == '2') {
        if (add_data.routeSimpleName == '拼车接天府') {
            // add_data.flightNum = land_se_list.value.flightNo
            // add_data.flightDate = add4hours(land_se_list.value.arrScheduled)
            if (land_se_list.value.depPort.indexOf('天府') != -1) {
                add_data.returnOrder.toLocation = '天府机场T' + land_se_list.value.depTerminal
            } else {
                return ElMessage({
                    message: '抱歉暂时只支持天府机场业务！',
                    type: 'warning',
                })
            }
        } else if (add_data.routeSimpleName == '拼车送天府') {
            // add_data.flightNum = land_se_list.value.flightNo

            // add_data.landDate = add30Minutes(land_se_list.value.arrScheduled)
            if (land_se_list.value.arrPort.indexOf('天府') != -1) {
                add_data.returnOrder.fromLocation = '天府机场T' + land_se_list.value.arrTerminal
            } else {
                return ElMessage({
                    message: '抱歉暂时只支持天府机场业务！',
                    type: 'warning',
                })
            }


        }
    } else {
        if (add_data.routeSimpleName == '拼车接天府') {
            add_data.flightNum = land_se_list.value.flightNo
            add_data.flightDate = add4hours(land_se_list.value.arrScheduled)
            add_data.landDate = add30Minutes(land_se_list.value.arrScheduled)
            if (land_se_list.value.arrPort.indexOf('天府') != -1) {
                add_data.fromLocation = '天府机场T' + land_se_list.value.arrTerminal
            } else {
                return ElMessage({
                    message: '抱歉暂时只支持天府机场业务！',
                    type: 'warning',
                })
            }
        } else if (add_data.routeSimpleName == '拼车送天府') {
            add_data.flightNum = land_se_list.value.flightNo
            add_data.flightDate = add4hours(land_se_list.value.arrScheduled)
            if (land_se_list.value.depPort.indexOf('天府') != -1) {
                add_data.toLocation = '天府机场T' + land_se_list.value.depTerminal
            } else {
                return ElMessage({
                    message: '抱歉暂时只支持天府机场业务！',
                    type: 'warning',
                })
            }
        }
    }


    land_se_off.value = false
}
//#endregion

//#region 酒店查询
const getStationList_Data = ref([])
const getStationList = () => {

    getStationListPages({
        page: {
            pageNum: 1,
            pageSize: 999,
        },
        stationTypes: ['HOTEL'],
    }).then(res => {
        if (res.code == 1) {
            getStationList_Data.value = res.data.list
        }
    })
}
const select_Btn = (e) => {
    if (add_data.routeSimpleName == '拼车接天府') {
        let list = {}
        for (let i = 0; i < getStationList_Data.value.length; i++) {
            if (e == getStationList_Data.value[i].stationName) {
                list = getStationList_Data.value[i]
            }

        }
        add_data.toLocation = list.stationName
        add_data.toLocationData.address = list.address
        add_data.toLocationData.id = list.id
        add_data.toLocationData.lnglat = list.lngLat
        add_data.toLocationData.tel = list.hotelLinkPhone
        console.log(add_data.toLocationData.id)
    } else if (add_data.routeSimpleName == '拼车送天府') {
        let list = {}
        for (let i = 0; i < getStationList_Data.value.length; i++) {
            if (e == getStationList_Data.value[i].stationName) {
                list = getStationList_Data.value[i]
            }

        }
        add_data.fromLocation = list.stationName
        add_data.fromLocationData.address = list.address
        add_data.fromLocationData.id = list.id
        add_data.fromLocationData.lnglat = list.lngLat
        add_data.fromLocationData.tel = list.hotelLinkPhone

    }

}
const select_Btn2 = (e) => {
    if (add_data.routeSimpleName == '拼车接天府') {
        let list = {}
        for (let i = 0; i < getStationList_Data.value.length; i++) {
            if (e == getStationList_Data.value[i].stationName) {
                list = getStationList_Data.value[i]
            }

        }
        // add_data.fromLocation = list.stationName
        add_data.returnOrder.fromLocationData.address = list.address
        add_data.returnOrder.fromLocationData.id = list.id
        add_data.returnOrder.fromLocationData.lnglat = list.lngLat
        add_data.returnOrder.fromLocationData.tel = list.hotelLinkPhone

    } else if (add_data.routeSimpleName == '拼车送天府') {
        let list = {}
        for (let i = 0; i < getStationList_Data.value.length; i++) {
            if (e == getStationList_Data.value[i].stationName) {
                list = getStationList_Data.value[i]
            }

        }

        // add_data.toLocation = list.stationName
        add_data.returnOrder.toLocationData.address = list.address
        add_data.returnOrder.toLocationData.id = list.id
        add_data.returnOrder.toLocationData.lnglat = list.lngLat
        add_data.returnOrder.toLocationData.tel = list.hotelLinkPhone
        console.log(add_data.toLocationData.id)
    }

}

// 

const toLocation_querySearch = (queryString, cb) => {
    let results = []
    getStationListPages({
        page: {
            pageNum: 1,
            pageSize: 5,
        },
        find: queryString,
    }).then(res => {
        if (res.code == 1) {
            res.data.list.forEach(it => {
                results.push({
                    id: it.id,
                    // 坐标
                    lnglat: it.lngLat,
                    // 名称
                    stationName: it.stationName,
                    // 地址
                    address: it.address,
                    // 电话
                    tel: it.hotelLinkPhone,
                    value: it.stationName

                });
            });
        }
        cb(results)
    })
}
const toLocation_handleSelect = (item) => {
    if (add_data.routeSimpleName == '拼车接天府') {
        add_data.toLocation = item.stationName
        add_data.toLocationData.address = item.address
        add_data.toLocationData.id = item.id
        add_data.toLocationData.lnglat = item.lngLat
        add_data.toLocationData.tel = item.hotelLinkPhone
    } else if (add_data.routeSimpleName == '拼车送天府') {
        add_data.fromLocation = item.stationName
        add_data.fromLocationData.address = item.address
        add_data.fromLocationData.id = item.id
        add_data.fromLocationData.lnglat = item.lngLat
        add_data.fromLocationData.tel = item.hotelLinkPhone
    }

}
//#endregion

//#region 地图
const myMap = ref('')
const geolocation = ref('') // 定位
const map_address = ref('')
const map_address_list = ref([])
const map_value = ref({})
const marker = ref('')
const map_off = ref(false)
const map_off_btn = (e) => {
    if (e == 2) {
        isReturn_map_off.value = e
    }
    // 地图
    window._AMapSecurityConfig = {
        securityJsCode: securityJsCode,
    }
    // 首次加载
    AMapLoader.load({
        key: key,
        version: '2.0',
        plugins: ['AMap.Driving', 'AMap.Geolocation', 'AMap.Scale', 'AMap.AutoComplete', 'AMap.PlaceSearch'],
    }).then((AMap) => {
        // 初始化-地图对象
        myMap.value = new AMap.Map('myMap', { zoom: 10, center: [104.065861, 30.657401] });
        // myMap.value.addControl(new AMap.Scale())
        // geolocation.value = new AMap.Geolocation({ //定位
        //     enableHighAccuracy: true, //是否使用高精度定位，默认:true
        //     convert: true, //自动偏移坐标 为高德坐标，默认：true
        //     timeout: 5000, //超过5秒后停止定位，默认：无穷大
        //     buttonPosition: 'RB', //定位按钮停靠位置
        //     showMarker: true, //定位成功在位置显示点标记，默认：true
        // })
        // myMap.value.addControl(geolocation.value)
        // geolocation.value.getCurrentPosition((status, result) => {
        //     console.log('定位getCurrentPosition', status, result);
        //     if (status == 'complete') {
        //         console.log('定位信息', result);
        //     } else {
        //         console.log('定位出错', result);
        //     }
        // })



    }).catch(err => { console.log('高德地图加载失败：', err); });
    map_off.value = true
}
const map_change = () => {
    let autoOptions = {
        city: '成都市'
    }
    var autoComplete = new AMap.Autocomplete(autoOptions);
    autoComplete.search(map_address.value, function (status, result) {
        // 搜索成功时，result即是对应的匹配数据
        map_address_list.value = result.tips.slice(0, 5)
    })
}




const map_list_btn = (e) => {
    console.log(e)
    map_address.value = e.district + '-' + e.address + '-' + e.name
    map_value.value = e

    myMap.value.panTo([e.location.lng, e.location.lat]);
    if (marker.value) {
        myMap.value.remove(marker.value);
    }
    myMap.value.setFitView();
    marker.value = new AMap.Marker({
        map: myMap.value,
        position: [e.location.lng, e.location.lat],
    });
    myMap.value.setFitView();
    myMap.value.add(marker.value);


}
const map_ok_btn = () => {
    if (isReturn_map_off.value == 2) {
        if (add_data.routeSimpleName == '拼车接天府') {
            add_data.returnOrder.fromLocation = map_value.value.name
            add_data.returnOrder.fromLocationData.address = map_value.value.district + map_value.value.address + map_value.value.name
            add_data.returnOrder.fromLocationData.id = map_value.value.id
            add_data.returnOrder.fromLocationData.lnglat = map_value.value.location.lng + ',' + map_value.value.location.lat
            add_data.returnOrder.fromLocationData.tel = ''

        } else if (add_data.routeSimpleName == '拼车送天府') {
            add_data.returnOrder.toLocation = map_value.value.name
            add_data.returnOrder.toLocationData.address = map_value.value.district + map_value.value.address + map_value.value.name
            add_data.returnOrder.toLocationData.id = map_value.value.id
            add_data.returnOrder.toLocationData.lnglat = map_value.value.location.lng + ',' + map_value.value.location.lat
            add_data.returnOrder.toLocationData.tel = ''
            console.log(add_data.toLocationData)
        }
    } else {
        if (add_data.routeSimpleName == '拼车接天府') {
            add_data.toLocation = map_value.value.name
            add_data.toLocationData.address = map_value.value.district + map_value.value.address + map_value.value.name
            add_data.toLocationData.id = map_value.value.id
            add_data.toLocationData.lnglat = map_value.value.location.lng + ',' + map_value.value.location.lat
            add_data.toLocationData.tel = ''
            console.log(add_data.toLocationData)
        } else if (add_data.routeSimpleName == '拼车送天府') {
            add_data.fromLocation = map_value.value.name
            add_data.fromLocationData.address = map_value.value.district + map_value.value.address + map_value.value.name
            add_data.fromLocationData.id = map_value.value.id
            add_data.fromLocationData.lnglat = map_value.value.location.lng + ',' + map_value.value.location.lat
            add_data.fromLocationData.tel = ''
        }
    }

    isReturn_map_off.value = ''
    console.log(isReturn_map_off.value)
    map_off.value = false

}
//#endregion

// 接机地点
const fromLocation_list = reactive([
    {
        value: '天府机场T1',
        label: '天府机场T1',
    },
    {
        value: '天府机场T2',
        label: '天府机场T2',
    },
])

// 合并标识
const isMerge_list = reactive([
    {
        value: 'true',
        label: '合并',
    },
    {
        value: 'false',
        label: '未合并',
    },
])

//#region 分页列表
const getServiceMans_list = ref([])
const list_data = ref([])
const find_data = reactive({
    page: {
        pageNum: 1,
        pageSize: 100,
    },
    payWay: '',
    routeSimpleName: '',
    // useCarCompanyId: '',
    // personNum: '',
    // startTime: '',
    // find: '',
    // shareMobile: '',
    // isMerge: '',
    companyNum: '',
    serviceMan: '',
    timeType: '0',
    stime: '',
    etime: '',
    orderByCondition: '0',
    orderNum: '',
    details: '',
    statusList: [],
    // serviceType: '',
    needSeats: '',
    plateNum: '',
    driverName: '',
    cusName: '',
    realName: '',
    useCarCompanyId: '',
    useCarDutyUserId: '',
    carCompanyId: '',
    carDutyUserId: '',
})
const total = ref(0)

// 分页器一夜显示多少数据页面
const size_change_btn = () => {
    find_data.page.pageNum = 1
    list_api()
}

// 分页器跳转页面
const current_change_btn = () => {
    list_api()
}

const list_api = () => {
    let serviceMan_data = find_data.serviceMan
    // if (find_data.serviceMan) {
    //     for (let i = 0; i < getServiceMans_list.value.length; i++) {
    //         if (find_data.serviceMan == getServiceMans_list.value[i].ftUserId) {
    //             find_data.serviceMan = getServiceMans_list.value[i].ftUserId + '-' + getServiceMans_list.value[i].realName + '-' + getServiceMans_list.value[i].loginPhone
    //         }
    //     }

    // }
    getOrderList(find_data).then(res => {
        list_data.value = res.data.list
        total.value = res.data.total
    })
}
//#endregion

//#region 添加
const add_off = ref(false)
const title = ref('添加订单')
const add_data = reactive({
    cusMobile: '', // 乘车人电话
    cusName: '', // 乘车人
    flightDate: '',// 航班起飞时间 yyyy-MM-dd HH:mm
    flightNum: "",// 航班号
    fromLocation: "",// 出发地名称
    fromLocationData: {
        address: '',
        area: '',
        id: "",
        isSta: "",
        lnglat: "",
        name: "",
        tel: "",
        type: ""
    },// 出发地
    fromLocationId: '',// 出发地主数据id(接天府肯定有)
    landDate: '',// 航班降落时间 yyyy-MM-dd HH:mm
    personNum: '',// 预约人数
    receiveMsg: '',// true通知,false不通知
    remark: '',// 备注
    routeSimpleName: '拼车接天府',// 行程简称,拼车接天府/拼车送天府
    toLocation: '',// 目的地名称
    toLocationData: {
        address: '',
        area: '',
        id: "",
        isSta: "",
        lnglat: "",
        name: "",
        tel: "",
        type: ""
    },// 目的地
    toLocationId: '',// 目的地主数据id(送天府肯定有)
    userId: '',// 用户Id,对应Customers表数据的id
    id: '',
    isReturnAdd: "",// 是否返程,true,false
    returnTime: '',// 返程时间,yyyy-MM-dd HH:mm:ss
    returnOrder: {
        fromLocation: "",// 出发地名称
        toLocation: '',// 目的地名称
        personNum: "",
        cusName: '',
        cusMobile: '',
        flightDate: '',// 航班起飞时间 yyyy-MM-dd HH:mm
        landDate: "", //航班降落时间 yyyy-MM-dd HH:mm
        fromLocationId: "",// 出发地主数据id(接天府肯定有)
        toLocationId: '',// 目的地主数据id(送天府肯定有)
        fromLocationData: {
            address: '',
            area: '',
            id: "",
            isSta: "",
            lnglat: "",
            name: "",
            tel: "",
            type: ""
        },// 出发地
        toLocationData: {
            address: '',
            area: '',
            id: "",
            isSta: "",
            lnglat: "",
            name: "",
            tel: "",
            type: ""
        },// 目的地
    }

})

const handleClick = (tab, event) => {
    add_data.routeSimpleName = tab.paneName
    console.log(add_data.routeSimpleName)
}

const add_btn = () => {

    title.value = '添加订单'
    add_data.cusMobile = ''
    add_data.cusName = ''
    add_data.flightDate = ''
    add_data.flightNum = ''
    add_data.fromLocation = ''
    add_data.fromLocationData.address = ''
    add_data.fromLocationData.area = ''
    add_data.fromLocationData.id = ''
    add_data.fromLocationData.isSta = ''
    add_data.fromLocationData.lnglat = ''
    add_data.fromLocationData.name = ''
    add_data.fromLocationData.tel = ''
    add_data.fromLocationData.type = ''
    add_data.fromLocationId = ''
    add_data.isReturnAdd = ''
    add_data.landDate = ''
    add_data.personNum = ''
    add_data.receiveMsg = ''
    add_data.remark = ''
    add_data.returnTime = ''
    add_data.routeSimpleName = '拼车接天府'
    add_data.toLocation = ''
    add_data.toLocationData.address = ''
    add_data.toLocationData.area = ''
    add_data.toLocationData.id = ''
    add_data.toLocationData.isSta = ''
    add_data.toLocationData.lnglat = ''
    add_data.toLocationData.name = ''
    add_data.toLocationData.tel = ''
    add_data.toLocationData.type = ''
    add_data.toLocationId = ''
    add_data.userId = ''
    add_data.id = ''

    add_data.returnOrder.fromLocation = ''
    add_data.returnOrder.toLocation = ''
    add_data.returnOrder.personNum = ''
    add_data.returnOrder.cusName = ''
    add_data.returnOrder.cusMobile = ''
    add_data.returnOrder.remark = ''
    add_data.returnOrder.flightDate = ''
    add_data.returnOrder.landDate = ''
    add_data.returnOrder.fromLocationId = ''
    add_data.returnOrder.toLocationId = ''
    add_data.returnOrder.fromLocationData.address = ''
    add_data.returnOrder.fromLocationData.area = ''
    add_data.returnOrder.fromLocationData.id = ''
    add_data.returnOrder.fromLocationData.isSta = ''
    add_data.returnOrder.fromLocationData.lnglat = ''
    add_data.returnOrder.fromLocationData.name = ''
    add_data.returnOrder.fromLocationData.tel = ''
    add_data.returnOrder.fromLocationData.type = ''
    add_data.returnOrder.toLocationData.address = ''
    add_data.returnOrder.toLocationData.area = ''
    add_data.returnOrder.toLocationData.id = ''
    add_data.returnOrder.toLocationData.isSta = ''
    add_data.returnOrder.toLocationData.lnglat = ''
    add_data.returnOrder.toLocationData.name = ''
    add_data.returnOrder.toLocationData.tel = ''
    add_data.returnOrder.toLocationData.type = ''

    add_off.value = true


}


//#endregion

//#region 表格选择
const table_list = ref([])
const selection_change_btn = (e) => {
    table_list.value = e
    console.log(e)
}
//#endregion
//#region 修改
const up_btn = () => {
    if (table_list.value.length != 1) {
        return ElMessage({
            message: '请选择一条数据！',
            type: 'warning',
        })
    }
    title.value = '修改订单'
    getOrderInfo({ id: table_list.value[0].id }).then(res => {
        let data_obj = res.data
        add_data.returnTime = data_obj.returnOrder ? data_obj.returnOrder.startTime : ''
        add_data.startTime = data_obj.order ? data_obj.order.startTime : ''
        add_data.cusMobile = data_obj.cusMobile
        add_data.cusName = data_obj.cusName
        add_data.flightDate = data_obj.flightDate
        add_data.flightNum = data_obj.flightNum
        add_data.fromLocation = data_obj.fromLocation
        add_data.fromLocationData.address = data_obj.fromLocationData.address
        add_data.fromLocationData.area = data_obj.fromLocationData.area
        add_data.fromLocationData.id = data_obj.fromLocationData.id
        add_data.fromLocationData.isSta = data_obj.fromLocationData.isSta
        add_data.fromLocationData.lnglat = data_obj.fromLocationData.lnglat
        add_data.fromLocationData.name = data_obj.fromLocationData.name
        add_data.fromLocationData.tel = data_obj.fromLocationData.tel
        add_data.fromLocationData.type = data_obj.fromLocationData.type
        add_data.fromLocationId = data_obj.fromLocationId
        add_data.isReturnAdd = data_obj.isReturnAdd == true ? '是' : '否'
        add_data.landDate = data_obj.landDate
        add_data.personNum = data_obj.personNum
        add_data.receiveMsg = data_obj.receiveMsg
        add_data.remark = data_obj.remark
        if (data_obj.routeSimpleName == '接天府' || data_obj.routeSimpleName == '送天府') {
            add_data.routeSimpleName = data_obj.routeSimpleName == '接天府' ? '拼车接天府' : '拼车送天府'
        } else {
            add_data.routeSimpleName = data_obj.routeSimpleName
        }

        add_data.toLocation = data_obj.toLocation
        add_data.toLocationData.address = data_obj.toLocationData.address
        add_data.toLocationData.area = data_obj.toLocationData.area
        add_data.toLocationData.id = data_obj.toLocationData.id
        add_data.toLocationData.isSta = data_obj.toLocationData.isSta
        add_data.toLocationData.lnglat = data_obj.toLocationData.lnglat
        add_data.toLocationData.name = data_obj.toLocationData.name
        add_data.toLocationData.tel = data_obj.toLocationData.tel
        add_data.toLocationData.type = data_obj.toLocationData.type
        add_data.toLocationId = data_obj.toLocationId
        add_data.userId = data_obj.userId
        add_data.id = data_obj.id

        add_data.returnOrder.fromLocation = ''
        add_data.returnOrder.toLocation = ''
        add_data.returnOrder.personNum = ''
        add_data.returnOrder.cusName = ''
        add_data.returnOrder.cusMobile = ''
        add_data.returnOrder.remark = ''
        add_data.returnOrder.flightDate = ''
        add_data.returnOrder.landDate = ''
        add_data.returnOrder.fromLocationId = ''
        add_data.returnOrder.toLocationId = ''
        add_data.returnOrder.fromLocationData.address = ''
        add_data.returnOrder.fromLocationData.area = ''
        add_data.returnOrder.fromLocationData.id = ''
        add_data.returnOrder.fromLocationData.isSta = ''
        add_data.returnOrder.fromLocationData.lnglat = ''
        add_data.returnOrder.fromLocationData.name = ''
        add_data.returnOrder.fromLocationData.tel = ''
        add_data.returnOrder.fromLocationData.type = ''
        add_data.returnOrder.toLocationData.address = ''
        add_data.returnOrder.toLocationData.area = ''
        add_data.returnOrder.toLocationData.id = ''
        add_data.returnOrder.toLocationData.isSta = ''
        add_data.returnOrder.toLocationData.lnglat = ''
        add_data.returnOrder.toLocationData.name = ''
        add_data.returnOrder.toLocationData.tel = ''
        add_data.returnOrder.toLocationData.type = ''
        if (data_obj.returnOrder) {
            add_data.returnOrder.fromLocation = data_obj.returnOrder.fromLocation
            add_data.returnOrder.toLocation = data_obj.returnOrder.toLocation
            add_data.returnOrder.personNum = data_obj.returnOrder.personNum
            add_data.returnOrder.cusName = data_obj.returnOrder.cusName
            add_data.returnOrder.cusMobile = data_obj.returnOrder.cusMobile
            add_data.returnOrder.remark = data_obj.returnOrder.remark
            add_data.returnOrder.flightDate = data_obj.returnOrder.flightDate
            add_data.returnOrder.landDate = data_obj.returnOrder.landDate
            add_data.returnOrder.fromLocationId = data_obj.returnOrder.fromLocationId
            add_data.returnOrder.toLocationId = data_obj.returnOrder.toLocationId
            add_data.returnOrder.fromLocationData.address = data_obj.returnOrder.fromLocationData.address
            add_data.returnOrder.fromLocationData.area = data_obj.returnOrder.fromLocationData.area
            add_data.returnOrder.fromLocationData.id = data_obj.returnOrder.fromLocationData.id
            add_data.returnOrder.fromLocationData.isSta = data_obj.returnOrder.fromLocationData.isSta
            add_data.returnOrder.fromLocationData.lnglat = data_obj.returnOrder.fromLocationData.lnglat
            add_data.returnOrder.fromLocationData.name = data_obj.returnOrder.fromLocationData.name
            add_data.returnOrder.fromLocationData.tel = data_obj.returnOrder.fromLocationData.tel
            add_data.returnOrder.fromLocationData.type = data_obj.returnOrder.fromLocationData.type
            add_data.returnOrder.toLocationData.address = data_obj.returnOrder.toLocationData.address
            add_data.returnOrder.toLocationData.area = data_obj.returnOrder.toLocationData.area
            add_data.returnOrder.toLocationData.id = data_obj.returnOrder.toLocationData.id
            add_data.returnOrder.toLocationData.isSta = data_obj.returnOrder.toLocationData.isSta
            add_data.returnOrder.toLocationData.lnglat = data_obj.returnOrder.toLocationData.lnglat
            add_data.returnOrder.toLocationData.name = data_obj.returnOrder.toLocationData.name
            add_data.returnOrder.toLocationData.tel = data_obj.returnOrder.toLocationData.tel
            add_data.returnOrder.toLocationData.type = data_obj.returnOrder.toLocationData.type
        }

    })



    add_off.value = true
}
//#endregion

//#region 时间增加30分钟
const add30Minutes = (dateTimeStr) => {
    let date = new Date(dateTimeStr);
    date.setMinutes(date.getMinutes() + 30);

    let year = date.getFullYear();
    let month = (date.getMonth() + 1).toString().padStart(2, '0');
    let day = date.getDate().toString().padStart(2, '0');
    let hours = date.getHours().toString().padStart(2, '0');
    let minutes = date.getMinutes().toString().padStart(2, '0');

    let newDateTimeStr = `${year}-${month}-${day} ${hours}:${minutes}`;
    return newDateTimeStr;
}

//#endregion

//#region 时间提前4个小时
// 定义表示时间的字符串
const add4hours = (dateString) => {
    console.log(dateString);
    // 将时间字符串转换为日期对象
    let dateObj = new Date(dateString);

    // 将时间提前4个小时
    dateObj.setHours(dateObj.getHours() - 4);

    // 格式化新的日期时间
    let year = dateObj.getFullYear();
    let month = ("0" + (dateObj.getMonth() + 1)).slice(-2);
    let day = ("0" + dateObj.getDate()).slice(-2);
    let hours = ("0" + dateObj.getHours()).slice(-2);
    let minutes = ("0" + dateObj.getMinutes()).slice(-2);

    let newDateString = year + "-" + month + "-" + day + " " + hours + ":" + minutes;

    console.log(newDateString);
    // 输出新的日期时间字符串
    return newDateString;


}
//#endregion

// 提交
const ok_btn = () => {
    let timeDate = new Date().getTime()
    if (add_data.flightDate) {
        let flightDate1 = new Date(add_data.flightDate).getTime()
        if (flightDate1 < timeDate) {
            return ElMessage({
                message: '时间不能小于当前时间',
                type: 'warning',
            })
        }
    }
    if (add_data.returnOrder.flightDate) {
        let flightDate2 = new Date(add_data.returnOrder.flightDate).getTime()
        if (flightDate2 < timeDate) {
            return ElMessage({
                message: '时间不能小于当前时间',
                type: 'warning',
            })
        }
    }
    if (add_data.landDate) {
        let landDate1 = new Date(add_data.landDate).getTime()
        if (landDate1 < timeDate) {
            return ElMessage({
                message: '时间不能小于当前时间',
                type: 'warning',
            })
        }
    }
    if (add_data.returnOrder.landDate) {
        let landDate2 = new Date(add_data.returnOrder.landDate).getTime()
        if (landDate2 < timeDate) {
            return ElMessage({
                message: '时间不能小于当前时间',
                type: 'warning',
            })
        }
    }


    let luser = JSON.parse(localStorage.getItem("luser"))
    add_data.userId = luser.uname
    if (add_data.routeSimpleName == '拼车接天府') {
        if (!add_data.landDate) {
            return ElMessage({
                message: '请选择接机时间',
                type: 'warning',
            })
        } else if (!add_data.fromLocation) {
            return ElMessage({
                message: '请选择接机地址',
                type: 'warning',
            })
        }
        else if (!add_data.toLocation) {
            return ElMessage({
                message: '请选择目的地址',
                type: 'warning',
            })
        }
    } else if (add_data.routeSimpleName == '拼车送天府') {
        if (!add_data.fromLocation) {
            return ElMessage({
                message: '请选择起始地址',
                type: 'warning',
            })
        } else if (!add_data.flightDate) {
            return ElMessage({
                message: '请选择送机时间',
                type: 'warning',
            })
        }
    }
    if (!add_data.personNum) {
        return ElMessage({
            message: '请输入预约人数',
            type: 'warning',
        })
    } else if (!add_data.cusName) {
        return ElMessage({
            message: '请输入乘车人姓名',
            type: 'warning',
        })
    } else if (!add_data.cusMobile) {
        return ElMessage({
            message: '请输入乘车人电话',
            type: 'warning',
        })
    } else if (!add_data.isReturnAdd) {
        return ElMessage({
            message: '请输入是否返程',
            type: 'warning',
        })
    }

    if (title.value == '添加订单') {

        if (add_data.isReturnAdd == 'true') {
            if (add_data.routeSimpleName == '拼车接天府') {
                add_data.returnTime = add_data.returnOrder.flightDate
                if (add_data.returnOrder.toLocationData.address == '天府机场T1') {
                    add_data.returnOrder.toLocationId = 2
                    add_data.returnOrder.toLocationData.address = '天府机场T1'
                    add_data.returnOrder.toLocationData.area = '简阳天府机场T1'
                    add_data.returnOrder.toLocationData.lnglat = "104.441364,30.312355"
                    add_data.fromLocationId = 2
                    add_data.fromLocationData.address = '天府机场T1'
                    add_data.fromLocationData.area = '简阳天府机场T1'
                    add_data.fromLocationData.lnglat = "104.441364,30.312355"
                } else {
                    add_data.returnOrder.toLocationId = 3
                    add_data.returnOrder.toLocationData.address = '天府机场T2'
                    add_data.returnOrder.toLocationData.area = '简阳天府机场T2'
                    add_data.returnOrder.toLocationData.lnglat = "104.447412,30.310215"
                    add_data.fromLocationId = 3
                    add_data.fromLocationData.address = '天府机场T2'
                    add_data.fromLocationData.area = '简阳天府机场T2'
                    add_data.fromLocationData.lnglat = "104.447412,30.310215"
                }


            } else if (add_data.routeSimpleName == '拼车送天府') {
                add_data.returnTime = add_data.returnOrder.landDate
                if (add_data.returnOrder.fromLocationData.address = '天府机场T1') {
                    add_data.returnOrder.fromLocationId = 2
                    add_data.returnOrder.fromLocationData.address = '天府机场T1'
                    add_data.returnOrder.fromLocationData.area = '简阳天府机场T1'
                    add_data.returnOrder.fromLocationData.lnglat = "104.441364,30.312355"
                    add_data.toLocationId = 2
                    add_data.toLocationData.address = '天府机场T1'
                    add_data.toLocationData.area = '简阳天府机场T1'
                    add_data.toLocationData.lnglat = "104.441364,30.312355"
                } else {
                    add_data.returnOrder.fromLocationId = 3
                    add_data.returnOrder.fromLocationData.address = '天府机场T2'
                    add_data.returnOrder.fromLocationData.area = '简阳天府机场T2'
                    add_data.returnOrder.fromLocationData.lnglat = "104.447412,30.310215"
                    add_data.toLocationId = 3
                    add_data.toLocationData.address = '天府机场T2'
                    add_data.toLocationData.area = '简阳天府机场T2'
                    add_data.toLocationData.lnglat = "104.447412,30.310215"
                }
            }
        } else {
            if (add_data.routeSimpleName == '拼车接天府') {
                if (add_data.fromLocation == '天府机场T1') {
                    add_data.fromLocationId = 2
                    add_data.fromLocationData.address = '天府机场T1'
                    add_data.fromLocationData.area = '简阳天府机场T1'
                    add_data.fromLocationData.lnglat = "104.441364,30.312355"
                } else {
                    add_data.fromLocationId = 3
                    add_data.fromLocationData.address = '天府机场T2'
                    add_data.fromLocationData.area = '简阳天府机场T2'
                    add_data.fromLocationData.lnglat = "104.447412,30.310215"
                }


            } else if (add_data.routeSimpleName == '拼车送天府') {
                if (add_data.fromLocation == '天府机场T1') {
                    add_data.toLocationId = 2
                    add_data.toLocationData.address = '天府机场T1'
                    add_data.toLocationData.area = '简阳天府机场T1'
                    add_data.toLocationData.lnglat = "104.441364,30.312355"
                } else {
                    add_data.toLocationId = 3
                    add_data.toLocationData.address = '天府机场T2'
                    add_data.toLocationData.area = '简阳天府机场T2'
                    add_data.toLocationData.lnglat = "104.447412,30.310215"
                }
            }
        }



        add(add_data).then(res => {
            if (res.code == 1) {
                list_api()
                add_off.value = false
                return ElMessage({
                    message: res.msg,
                    type: 'success',
                })
            } else {
                list_api()
                add_off.value = false
                return ElMessage({
                    message: res.msg,
                    type: 'warning',
                })
            }
        })
    } else {
        if (add_data.isReturnAdd == '是') {
            add_data.isReturnAdd = true
        } else {
            add_data.isReturnAdd = false
        }

        if (add_data.isReturnAdd == 'true') {
            if (add_data.routeSimpleName == '拼车接天府') {
                add_data.returnTime = add_data.returnOrder.flightDate
                if (add_data.returnOrder.toLocationData.address == '天府机场T1') {
                    add_data.returnOrder.toLocationId = 2
                    add_data.returnOrder.toLocationData.address = '天府机场T1'
                    add_data.returnOrder.toLocationData.area = '简阳天府机场T1'
                    add_data.returnOrder.toLocationData.lnglat = "104.441364,30.312355"
                    add_data.fromLocationId = 2
                    add_data.fromLocationData.address = '天府机场T1'
                    add_data.fromLocationData.area = '简阳天府机场T1'
                    add_data.fromLocationData.lnglat = "104.441364,30.312355"
                } else {
                    add_data.returnOrder.toLocationId = 3
                    add_data.returnOrder.toLocationData.address = '天府机场T2'
                    add_data.returnOrder.toLocationData.area = '简阳天府机场T2'
                    add_data.returnOrder.toLocationData.lnglat = "104.447412,30.310215"
                    add_data.fromLocationId = 3
                    add_data.fromLocationData.address = '天府机场T2'
                    add_data.fromLocationData.area = '简阳天府机场T2'
                    add_data.fromLocationData.lnglat = "104.447412,30.310215"
                }


            } else if (add_data.routeSimpleName == '拼车送天府') {
                add_data.returnTime = add_data.returnOrder.landDate
                if (add_data.returnOrder.fromLocationData.address = '天府机场T1') {
                    add_data.returnOrder.fromLocationId = 2
                    add_data.returnOrder.fromLocationData.address = '天府机场T1'
                    add_data.returnOrder.fromLocationData.area = '简阳天府机场T1'
                    add_data.returnOrder.fromLocationData.lnglat = "104.441364,30.312355"
                    add_data.toLocationId = 2
                    add_data.toLocationData.address = '天府机场T1'
                    add_data.toLocationData.area = '简阳天府机场T1'
                    add_data.toLocationData.lnglat = "104.441364,30.312355"
                } else {
                    add_data.returnOrder.fromLocationId = 3
                    add_data.returnOrder.fromLocationData.address = '天府机场T2'
                    add_data.returnOrder.fromLocationData.area = '简阳天府机场T2'
                    add_data.returnOrder.fromLocationData.lnglat = "104.447412,30.310215"
                    add_data.toLocationId = 3
                    add_data.toLocationData.address = '天府机场T2'
                    add_data.toLocationData.area = '简阳天府机场T2'
                    add_data.toLocationData.lnglat = "104.447412,30.310215"
                }
            }
        } else {
            if (add_data.routeSimpleName == '拼车接天府') {
                if (add_data.fromLocation == '天府机场T1') {
                    add_data.fromLocationId = 2
                    add_data.fromLocationData.address = '天府机场T1'
                    add_data.fromLocationData.area = '简阳天府机场T1'
                    add_data.fromLocationData.lnglat = "104.441364,30.312355"
                } else {
                    add_data.fromLocationId = 3
                    add_data.fromLocationData.address = '天府机场T2'
                    add_data.fromLocationData.area = '简阳天府机场T2'
                    add_data.fromLocationData.lnglat = "104.447412,30.310215"
                }


            } else if (add_data.routeSimpleName == '拼车送天府') {
                if (add_data.fromLocation == '天府机场T1') {
                    add_data.toLocationId = 2
                    add_data.toLocationData.address = '天府机场T1'
                    add_data.toLocationData.area = '简阳天府机场T1'
                    add_data.toLocationData.lnglat = "104.441364,30.312355"
                } else {
                    add_data.toLocationId = 3
                    add_data.toLocationData.address = '天府机场T2'
                    add_data.toLocationData.area = '简阳天府机场T2'
                    add_data.toLocationData.lnglat = "104.447412,30.310215"
                }
            }
        }


        edit(add_data).then(res => {
            if (res.code == 1) {
                list_api()
                add_off.value = false
                return ElMessage({
                    message: res.msg,
                    type: 'success',
                })
            } else {
                list_api()
                add_off.value = false
                return ElMessage({
                    message: res.msg,
                    type: 'warning',
                })
            }
        })
    }
}

const isReturnAdd_change = (e) => {
    console.log(e)
    if (e == 'true') {

        add_data.returnOrder.personNum = add_data.personNum
        add_data.returnOrder.cusName = add_data.cusName
        add_data.returnOrder.cusMobile = add_data.cusMobile
        add_data.returnOrder.remark = add_data.remark
        if (add_data.routeSimpleName == '拼车接天府') {
            add_data.returnOrder.fromLocation = add_data.toLocation
            add_data.returnOrder.fromLocationId = add_data.toLocationId
            add_data.returnOrder.fromLocationData.address = add_data.toLocationData.address
            add_data.returnOrder.fromLocationData.area = add_data.toLocationData.area
            add_data.returnOrder.fromLocationData.id = add_data.toLocationData.id
            add_data.returnOrder.fromLocationData.isSta = add_data.toLocationData.isSta
            add_data.returnOrder.fromLocationData.lnglat = add_data.toLocationData.lnglat
            add_data.returnOrder.fromLocationData.name = add_data.toLocationData.name
            add_data.returnOrder.fromLocationData.tel = add_data.toLocationData.tel
            add_data.returnOrder.fromLocationData.type = add_data.toLocationData.type

        } else {
            add_data.returnOrder.toLocation = add_data.fromLocation
            add_data.returnOrder.toLocationId = add_data.fromLocationId
            add_data.returnOrder.toLocationData.address = add_data.fromLocationData.address
            add_data.returnOrder.toLocationData.area = add_data.fromLocationData.area
            add_data.returnOrder.toLocationData.id = add_data.fromLocationData.id
            add_data.returnOrder.toLocationData.isSta = add_data.fromLocationData.isSta
            add_data.returnOrder.toLocationData.lnglat = add_data.fromLocationData.lnglat
            add_data.returnOrder.toLocationData.name = add_data.fromLocationData.name
            add_data.returnOrder.toLocationData.tel = add_data.fromLocationData.tel
            add_data.returnOrder.toLocationData.type = add_data.fromLocationData.type
        }

    }
}

//#region 删除
const del_btn = () => {
    if (table_list.value.length < 1) {
        return ElMessage({
            message: '请选择数据！',
            type: 'warning',
        })
    }

    ElMessageBox.confirm(
        '是否确认删除客户?',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
            distinguishCancelAndClose: 'true',
        }
    )
        .then(() => {
            let ps = []
            for (let i = 0; i <= table_list.value.length; i++) {
                ps.push(table_list.value[0].id)
            }

            omsorderdelete({
                ids: ps
            }).then(res => {
                if (res.code == 1) {
                    list_api()
                    return ElMessage({
                        message: res.msg,
                        type: 'success',
                    })
                } else {
                    return ElMessage({
                        message: res.msg,
                        type: 'warning',
                    })
                }
            })
        })
        .catch((e) => {
            if (e == 'cancel') {
                ElMessage({
                    type: 'warning',
                    message: '取消删除成功',
                })
            }

        })

}
//#endregion

//#region 搜索
const search_btn = () => {
    localStorage.setItem('original_order_list', CircularJSON.stringify(find_data))
    list_api()
}
//#endregion


//#region 订单导出
const out_btn = () => {
    // if (table_list.value.length != 1) {
    //     return ElMessage({
    //         message: '请选择数据一条数据！',
    //         type: 'warning',
    //     })
    // }
    // let response = await omsorderexport({ id: table_list.value[0].id })
    // let url = window.URL.createObjectURL(new Blob([response.data])); // 创建包含响应数据的 Blob 对象
    // const link = document.createElement('a'); // 创建一个隐藏的链接元素
    // link.href = url;
    // link.setAttribute('download', '原始订单列表.xlsx'); // 设置文件名
    // document.body.appendChild(link); // 将链接元素添加到文档中
    // link.click(); // 模拟点击链接进行下载
    // link.remove(); // 下载完成后移除链接元素


    omsorderexport(find_data).then(res => {

        if (res.code == 1) {
            const data = [
                ['订单号', '行程简称', '订单状态', '人数', '航班号', '出发日期', '可等待时间', '起点', '终点', '乘车人', '推广人', '订单价格', '客户备注', '用车单位', '用车负责人', '合并标识', '添加时间'],
            ];
            for (let i = 0; i < res.data.length; i++) {
                let ps = {
                    orderNum: res.data[i].orderNum,
                    routeSimpleName: res.data[i].routeSimpleName,
                    status: res.data[i].status == 'READY_CAR' ? '未派车' : res.data[i].status == 'CAR_READY_CONFIRME' ? '待确认' : res.data[i].status == 'DRIVER_READY_RECEIVE' ? '待接单' : res.data[i].status == 'READY_ROAD' ? '未出行' : res.data[i].status == 'ON_ROADING' ? '未完团' : res.data[i].status == 'FINISHED' ? '完成' : '',
                    personNum: res.data[i].personNum,
                    flightNum: res.data[i].flightNum,
                    flightDate: res.data[i].flightDate,
                    waitDate: res.data[i].waitDate,
                    fromLocation: res.data[i].fromLocation,
                    toLocation: res.data[i].toLocation,
                    personNum: res.data[i].cusName + '-' + res.data[i].cusMobile,
                    shareName: res.data[i].shareName + '-' + res.data[i].shareMobile,
                    price: res.data[i].price,
                    remark: res.data[i].remark,
                    useCarCompanyId: res.data[i].useCarCompanyId,
                    useCarName: res.data[i].useCarName,
                    isMerge: res.data[i].isMerge == true ? '合并' : '未合并',
                    addTime: res.data[i].addTime,

                }
                data.push(Object.values(ps))
            }
            const ws = XLSX.utils.aoa_to_sheet(data);
            const wb = XLSX.utils.book_new();
            XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
            XLSX.writeFile(wb, '单位管理系统-订单列表.xlsx');
            list_api()
            return ElMessage({
                message: res.msg,
                type: 'success',
            })
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }

    })

}
//#endregion
</script>

<style scoped lang='scss'>
.div_map {
    position: relative;
    left: 0;
    top: 0;
}

.map_input {
    width: 100%;
    position: absolute;
    z-index: 1;
    display: flex;
    justify-content: center;

}

.map_input2 {
    width: 100%;
    position: absolute;
    z-index: 1;
    display: flex;
    justify-content: center;
    top: 34px;

}

.div_bg:hover {


    background-color: darkgray;
}
</style>

<style>
.col-items::-webkit-scrollbar {
    width: 5px !important;
}

.col-items>label {
    margin-left: 0px !important;
    margin-top: 5px;
    width: 100%;
}

.el-table .el-table__cell {
    padding: 0px !important;
}

#tab-拼车接天府 {
    color: blue;
}

#tab-拼车送天府 {
    color: red;
}
</style>
